<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Đăng tin - CTV</title>
<link href="ctv.css" rel="stylesheet" type="text/css" />
<link href="favicon.ico" rel="shortcut icon" type="image/x-icon">
<?php 
	session_start();
	if($_SESSION["CTV"]==NULL)echo "<SCRIPT LANGUAGE='JavaScript'>
							  window.location.href='http://".$_SERVER['HTTP_HOST']."'/';
							  </SCRIPT>";
?>
</head>

<body style="margin:0px;">
<div id="contact">
    <?php
		include('Admin/php/connect-db.php');
		if(isset($_SESSION['username'])) {
			$sql10=mysql_query("select * from thongtin_user where username='".$_SESSION['username']."' and id_role='1'");
			if(mysql_num_rows($sql10)==1) { $a='Admin';$_SESSION["admin"]=1;};
		echo "<table align='right'>";
		echo "<tr><td style='padding-top:0px'><a href='http://".$_SERVER['HTTP_HOST']."'/index_tk.php'><img src='image\search.jpg' height='24px' width='42px' ></a></td>";
		echo "<td id='login_ok' colspan='2' align='center' style=\"line-height:15px; padding-left:22px\">Xin chào: ".$_SESSION['username'];if(mysql_num_rows($sql10)==1) print" <a href='http://".$_SERVER['HTTP_HOST']."/Admin/login.php' style='color:#fff'>(".$a.")</a> "; echo"</td>";
		echo "<td><a href='http://".$_SERVER['HTTP_HOST']."'/thongtin.php' style='font-size:13px; font-family:arial; padding-bottom:5px;color:#FFF; padding-right:10px;padding-left:10px ;text-decoration:none'>Đổi mật khẩu</a></td>";
		echo "<td><a href='http://".$_SERVER['HTTP_HOST']."'/index.php?logout=out' style='font-size:13px; font-family:arial;color:#FFF; padding-bottom:5px;text-decoration:none'>Đăng xuất</a></td></tr></table>";}
		else{ 
		echo "<table align='right'>";
		echo "<tr><td style='padding-top:0px'><a href='http://".$_SERVER['HTTP_HOST']."'/index_tk.php'><img src='image\search.jpg' height='24px' width='42px' ></a></td>";
		echo "<td><a href='http://".$_SERVER['HTTP_HOST']."'/login.php' style='font-size:13px;font-family:arial; text-decoration:none ;color:#FFF; padding-right:30px; padding-left:22px'>Đăng nhập</a>"; echo "</td>";
		echo "<td><a href='http://".$_SERVER['HTTP_HOST']."'/register.php' style='font-size:13px; font-family:arial; text-decoration:none; color:#FFF'>Đăng ký</a></td></tr></table>";
		}
			if(isset($_GET["logout"])){
			if(($_GET["logout"])=='out'){
				session_start();
				session_destroy();//delete session
				header("Location:http://".$_SERVER['HTTP_HOST']);
			}	}
    ?>

    </div>
<div id="main">
<div id="head">
	<?php echo"<a href='http://".$_SERVER['HTTP_HOST']."'><div id=\"logo\"></div></a>"; ?>
    <div id="quangcaotop">
   <?php
		$sql=mysql_query("select * from quangcao where vitri='1' and trangthai='active'");
		if(mysql_num_rows($sql)==1){
		$duyet=mysql_fetch_row($sql);
		if($duyet) print "<a href='$duyet[1]'><img src='http://".$_SERVER['HTTP_HOST']."/$duyet[0]' height='120px' width='750px'></a>";}
		else print "<img src=\"images/adv.png\" height='120px' width='750px'> ";
	?>
    </div>    
</div>
<div id="menutab">
	<ul>
    	<?php
		include('Admin/php/connect-db.php');
		$a=mysql_query("select * from chuyenmuc");
		$b=mysql_fetch_row($a);
    	echo"<li><a href='http://".$_SERVER['HTTP_HOST']."/'>Home</a></li>";
        echo"<li><a href='http://".$_SERVER['HTTP_HOST']."/theloai.php?id_cm=XH'>Xã hội</a></li>";
    	echo"<li><a href='http://".$_SERVER['HTTP_HOST']."/theloai.php?id_cm=PL'>Pháp luật</a></li>";
        echo"<li><a href='http://".$_SERVER['HTTP_HOST']."/theloai.php?id_cm=KT'>Kinh tế</a></li>";
        echo"<li><a href='http://".$_SERVER['HTTP_HOST']."/theloai.php?id_cm=NST'>Nhịp sống trẻ</a></li>";
        echo"<li><a href='http://".$_SERVER['HTTP_HOST']."/theloai.php?id_cm=VH-GT'>Văn hóa - Giải trí</a></li>";
        echo"<li><a href='http://".$_SERVER['HTTP_HOST']."/theloai.php?id_cm=TT'>Thể thao</a></li>";
        echo"<li><a href='http://".$_SERVER['HTTP_HOST']."/theloai.php?id_cm=TG'>Thế giới</a></li>";
        echo"<li><a href='http://".$_SERVER['HTTP_HOST']."/theloai.php?id_cm=TS'>Tâm sự</a></li>";
        echo"<li><a href='http://".$_SERVER['HTTP_HOST']."/theloai.php?id_cm=GD'>Giáo dục</a></li>";
 		?>
	</ul> 
</div>
<div id="dangbai">
<form action="ctv.php" method="post" enctype="multipart/form-data" autocomplete="on" >
			<table border="0" width="1000" align="center" cellspacing="20" style="margin-top:10px; " >
	    <tr>
	      <td colspan="2" align="center" style="font-family:Tahoma, Geneva, sans-serif; font-size:30px; color:#DF22B9;">ĐĂNG BÀI VIẾT<br /></td>
        </tr>
	    <tr>
	      <td align="right" id="td" style="font-size:14px;" width="150" ><b>
		  Chọn chuyên mục: </b></td>
		  <td align="left" valign="bottom" >
		  	<input name="id_CM" list="browsers" title="Vui lòng Không để trống." id="textbox" style="width:150px" placeholder=" * Chuyên mục" required="required">
			  <datalist id="browsers">
				<option value="GD">GIÁO DỤC
				<option value="KT">KINH TẾ
				<option value="NST">NHỊP SỐNG TRẺ
				<option value="PL">PHÁP LUẬT
				<option value="TG">THẾ GIỚI
				<option value="TS">TÂM SỰ
				<option value="TT">THỂ THAO
				<option value="VH-GT">VĂN HÓA - GIẢI TRÍ
				<option value="XH">XÃ HỘI
			  </datalist>
		  </td>
        </tr>
	    <tr>
	      <td align="right" id="td" style="font-size:14px; " ><b><br>Chọn loại tin: </b></td>
		  <td align="left" valign="bottom" >
		  	<select name="id_LT" id="textbox" style="width:150px" >
				<option value="TT">Tin tức</option>
				<option value="TA">Tin ảnh</option>
				<option value="TV">Tin video</option>
			</select>
		  </td>
        </tr>
		<tr>
		  <td align="right" valign="top" id="td" style="font-size:14px; " ><b><br>Avatar bài dăng: </b></td>
		  <td align="left" valign="bottom"><input type="file" name="image" id="textbox" required="required" accept="image/*" title="Vui lòng chọn file hình *MAX 1MB" /><font style="color:#F00;text-align:left; padding-left:20px">*(.jpg .jpge .png .gif)</font></td>
		</tr>
		<tr>
		  <td align="right"  valign="top" id="td" style="font-size:14px"><b><br>Tiêu đề: </b></td>
		  <td align="left" valign="bottom" ><input type="text" id="textbox1" name="tieude" required="required"  placeholder=" * Tiêu đề" title="Vui lòng Không để trống." ></td>
		</tr>
		<tr>
		  <td align="right" valign="top" id="td" style="font-size:14px" ><b>Tóm tắt: </b></td>
		  <td align="left" ><textarea rows="4" cols="75" name="tomtat"  id="textbox2" required="required" id="bo"  placeholder=" * Tóm tắt" title="Vui lòng không để trống." ></textarea></td>
		</tr>
		<tr>
		  <td id="td" align="right" valign="top" style="font-size:14px" ><b>Nội dung: </b></td>
		  <td align="left" ><?php include('ckeditor.php') ?></td></td>
		</tr>
	    <tr>
	      <td colspan="2" align="center"><br><input type="submit" name="add" id="button" value="Hoàn thành" onclick="return confirm(\'Bạn có chắc chắn là Hoàn thành không ?\')" /></td>
        </tr>
      </table>
     </form>
     

<?php 
	if(isset($_POST['add'])){
	include('Admin/php/connect-db.php');
	include('upload.php');

	  $id_CM = $_POST['id_CM'];
	  $id_LT = $_POST['id_LT'];
	  $avatar_tin = 'images/'.$image_name;

	  $tieude = $_POST['tieude'];
	  $tomtat = $_POST['tomtat'];
	  $noidung = $_POST['noidung'];
	  /*$sql = "UPDATE tintuc SET noidung='$noidung' WHERE id_tin='66'";*/
	  $sql = "insert into tintuc (id_CM, id_LT, ngay_dang, username, tieude, tomtat, noidung, avatar_tin) values ('".$id_CM."', '".$id_LT."',now(), '".$_SESSION['username']."', '".$tieude."', '".$tomtat."','$noidung', '$avatar_tin')";
	  if($noidung == '')echo "<SCRIPT LANGUAGE='JavaScript'>
							  window.alert('Vui lòng không để trống nội dung.')
							  window.history.go(-1);
							  </SCRIPT>";
	  if( !$errors && $noidung != ''){
	  $query = mysql_query($sql);
				if($query){echo "<SCRIPT LANGUAGE='JavaScript'>
				window.alert('Gửi tin tức thành công.')
				</SCRIPT>";}
				else echo "<SCRIPT LANGUAGE='JavaScript'>
				window.alert('Thêm không thành công.')
				window.history.go(-1);
				</SCRIPT>";
	  }
	}
?>     
</div>
    <?php

	$_SESSION['trove'] = $_SERVER['REQUEST_URI'];
?>
</body>
</html>